
<template>
    <LoadingComponent v-if="isLoading"></LoadingComponent>
</template>

<script type="text/javascript">
    import LoadingComponent from 'components/loading'
    import qs from 'qs'
    export default {
        components: { LoadingComponent },
        props: ['data'],
        data () {
            return {
                isLoading:false,
            }
        },
        created () {
            this.alertError();
            console.log(this.data)
        },
        methods: {
            alertError () {
                this.$confirm(this.data.title, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    this.isLoading = true;
                    this.$store.state.loading = true;
		                var logininfo = JSON.parse(localStorage.logininfo) ;
                    var logininfo = JSON.parse(localStorage.logininfo);
            				var params3 = qs.stringify({
            					yhid: logininfo.id,
            				    xxid:logininfo.xxid,
            					ids:this.data.index
            				});
                        this.axios.post(this.$store.state.api + 'wprkd/deletepl',  params3 ).then( res => {
                            if (res.data.code == 1) {
                                this.isLoading = false;
                                this.$message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                                if (this.data.type == 'single') {
                                    this.$emit('close',{type:'singleDelete',cancel:false})
                                }else{
                                    this.$emit('close',{type:'multipleDelete',cancel:false})
                                }
                            }else{
                                this.isLoading = false;
                                if (this.data.type == 'single') {
                                    this.$emit('close',{type:'singleDelete',cancel:false})
                                }else{
                                    this.$emit('close',{type:'multipleDelete',cancel:false})
                                }
                            }
                        }).catch( res => {
                            this.$store.state.loading = false;
                            this.$store.dispatch('showAlert',res.data.msg)
                            if (this.data.type == 'single') {
                                this.$emit('close',{type:'singleDelete',cancel:true})
                            }else{
                                this.$emit('close',{type:'multipleDelete',cancel:true})
                            }
                        })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                   if (this.data.type == 'single') {
                        this.$emit('close',{type:'singleDelete',cancel:true})
                    }else{
                        this.$emit('close',{type:'multipleDelete',cancel:true})
                    }
                });
            }
        }
    }
</script>
